<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>组合继承</title>
</head>
<body>
    <script>
        // 组合继承是原型链继承和构造继承的组合
        function Animal (name) {
            this.name = name
        }
        Animal.prototype.say = function () {
            console.log('My name is ' + this.name)
        }

        function Pig (name) {
            Animal.call(this, name)
        }
        Pig.prototype = new Animal()

        var peiqi = new Pig('Peiqi')
        peiqi.say()

        var qiaozhi = new Pig('Qiaozhi')
        qiaozhi.say()

        console.log(peiqi.say === qiaozhi.say) // true

        console.log(peiqi instanceof Pig)
        console.log(peiqi instanceof Animal)


    </script>
</body>
</html>